package cn.com.reflect;

import cn.com.domain.Person;

import java.lang.reflect.Method;

public class ReflectDemo3 {
    public static void main(String[] args)  throws Exception{
        Class personClass = Person.class;

        //获取public方法
        Method[] methods = personClass.getMethods();
        for (Method mother1:methods
             ) {
            System.out.println(mother1);
        }

        Person person=new Person();
        Method eat = personClass.getMethod("eat");
        eat.invoke(person);
        personClass.getMethod("eat", String.class).invoke(person,"饭");

        System.out.println("----------------------------------------------------");

        Method[] declaredMethods = personClass.getDeclaredMethods();
        for (Method method2:declaredMethods
             ) {
            System.out.println(method2);
        }

        System.out.println("---------------------------------------------------");


        Method run = personClass.getDeclaredMethod("run");
        run.setAccessible(true);
        run.invoke(person);
        Method run1 = personClass.getDeclaredMethod("run", String.class);
        run1.setAccessible(true);
        run1.invoke(person,"步");

        System.out.println("----------------------------------------");
        String name = personClass.getName();
        System.out.println(name);

        String name1 = personClass.getMethod("eat").getName();
        System.out.println(name1);

    }
}
